//
//  LZLeadingViewPresenter.m
//  laziz_Merchant
//
//  Created by xbn_iMac on 2017/1/12.
//  Copyright © 2017年 XBN. All rights reserved.
//

#import "LZLeadingViewPresenter.h"
#import <GVUserDefaults/GVUserDefaults.h>

static NSString *const lzShowLeadingViewMinVersionNum = @"1.0.0";    // 显示引导页的最小版本号

@interface GVUserDefaults (LZLeadingViewStoreVersionNum)

@property (nonatomic, copy)     NSString *  storVersionNum;

@end

@implementation GVUserDefaults (LZLeadingViewStoreVersionNum)

@dynamic storVersionNum;

@end

@implementation LZLeadingViewPresenter

+ (BOOL)isShowLeadingView {
    LZLeadingViewPresenter *presenter = [[LZLeadingViewPresenter alloc] init];
    
    return [presenter isShow];
    
}

- (BOOL)isShow {
    
    NSString *showLeadingViewMinVersionNum = [self showLeadingViewMinVersionNum];
    NSString *storLeadingViewVersionNum = [self storVersionNum];
    
    BOOL isShowLeadingView = NO;
    if (storLeadingViewVersionNum.length == 0) {
        isShowLeadingView = YES;
    }
    else {
        if ([showLeadingViewMinVersionNum isEqualToString:storLeadingViewVersionNum]) {
            isShowLeadingView = NO;
        }
        else {
            if ([showLeadingViewMinVersionNum compare:storLeadingViewVersionNum options:NSNumericSearch] == NSOrderedDescending)
                
            {
                DLog(@"%@ is bigger",showLeadingViewMinVersionNum);
                isShowLeadingView = YES;
            }
            
            else    {
                DLog(@"%@ is bigger",storLeadingViewVersionNum);
                isShowLeadingView = NO;
            }
        }
    }
    return isShowLeadingView;
}

// 最小支持版本号
- (NSString*)showLeadingViewMinVersionNum {
    return lzShowLeadingViewMinVersionNum;
}

// 上次展示leading的版本号
- (NSString*)storVersionNum {
    return [GVUserDefaults standardUserDefaults].storVersionNum;
}

// 保存当前版本号
+ (void)storNowVersionNum {
    [GVUserDefaults standardUserDefaults].storVersionNum = lzShowLeadingViewMinVersionNum;
}

@end
